package com.itheima.homework;

import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

public class ParseTest2 {
    public static void main(String[] args) throws DocumentException {
        SAXReader saxReader = new SAXReader();
        Document read = saxReader.read(new File("Day17_xml\\xml\\student.xml"));
        Element rootElement = read.getRootElement();
        List<Element> elements = rootElement.elements();
        ArrayList<User> alu = new ArrayList<>();
        for (Element element : elements) {
            String id = element.attributeValue("id");
            String name = element.elementText("name");
            String password = element.elementText("password");
            User user = new User(id,password,name);
            alu.add(user);
        }
        for (User user : alu) {
            System.out.println(user);
        }
    }
}
